<template>
  <div>
    <!-- 删除弹框 -->
    <el-dialog width="560px" title="删除提示" :visible.sync="dialogVisible">
      <div class="content">
        <div v-if="detailInfos.taskType == 3">
          <div class="line-one">
            <div class="line-box">
              <img
                class="mr-4"
                src="../../assets/images/data/resource/mark.png"
                alt=""
              />
              <span class="confirm-font"
                >您将删除此周期任务，请选择生效范围</span
              >
            </div>
          </div>
          <div class="box-checkbox">
            <el-radio-group v-model="radio" style="margin-bottom: 24px">
              <el-radio label="1" style="display: block; margin-bottom: 12px"
                >仅本次子任务。本次子任务当前进度状态为:<span
                  style="color: #ffad30"
                  >{{ statusMap[status] }}</span
                ></el-radio
              >
              <el-radio label="2">整个周期任务</el-radio>
            </el-radio-group>
          </div>
        </div>
        <div v-else class="line-one">
          <div class="line-box" style="justify-content: center">
            <img
              class="mr-4"
              src="../../assets/images/data/resource/mark.png"
              alt=""
            />
            <span class="confirm-font">当前子任务的进度状态为： </span
            ><span style="color: #ffad30">{{ statusMap[status] }}</span>
            <span class="confirm-font">。请确认是否删除此子任务？</span>
          </div>
        </div>
        <div class="obj-text">
          {{ $t("各进度状态下，子任务删除的业务逻辑如下：") }}<br />
          {{ $t("(1)等待执行：直接删除") }}<br />
          {{ $t("(2)任务超期：直接删除") }}<br />
          {{ $t("(3)正在执行：强制终止，不删除") }}<br />
          {{ $t("(4)任务暂停：强制终止，不删除") }}<br />
          {{ $t("(5)执行完成：不删除") }}<br />
          {{ $t("(6)中途终止：不删除") }}<br />
        </div>
      </div>

      <div slot="footer" style="display: flex; justify-content: flex-end">
        <div @click="confirmDelete" class="serch-btn">{{ $t("确认") }}</div>
        <div
          class="reset-btn"
          style="margin-left: 15px"
          @click="dialogVisible = false"
        >
          {{ $t("取消") }}
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { API_delTask } from "@/api/task/manage";
import { API_calendarDelete } from "@/api/task/calendar.js";
import { API_taskControl } from "@/api/robot/monitor";
export default {
  props: {
    detailInfos: {
      type: Object,
      default: () => {},
    },
    status: {
      type: String,
      default: "",
    },
    text: {
      type: Number,
      default: 1,
    },
    execId: {
      type: String,
      default: "",
    },
    taskId: {
      type: String,
      default: "",
    },
    rowTaskId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      dialogVisible: false,
      radio: "1",
      statusMap: {
        0: "等待执行",
        1: "等待执行",
        2: "任务超期",
        3: "正在执行",
        4: "任务暂停",
        5: "执行完成",
        6: "中途停止",
      },
      taskExecId: "",
    };
  },
  created() {},
  methods: {
    open(taskExecId) {
      this.dialogVisible = true;
      this.taskExecId = taskExecId;
    },
    // 确认删除
    confirmDelete() {
      if (this.detailInfos.taskType == 3) {
        if (this.radio == "2") {
          //删除整个周期任务
          const loading = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          // 有任务正在执行
          if (this.taskId != -1 && this.taskId == this.rowTaskId) {
            // 终止正在执行的
            API_taskControl({
              cmd: "3X13",
              values: [this.taskId, this.execId],
            })
              .then((res) => {
                if (res.code == 200 && res.data.nerrcode == 0) {
                  this.$message({
                    type: "success",
                    message: this.$t("任务已强制终止"),
                  });
                } else {
                  this.$message.error(this.$t("终止失败请重试"));
                }
              })
              .finally(() => {
                loading.close();
              });
            API_delTask([this.detailInfos.taskId])
              .then((res) => {
                if (res.code == 200) {
                  this.$message.success(this.$t("删除成功"));
                  this.dialogVisible = false;
                  this.$emit("closeTaskModal");
                  this.$emit("getDataList");
                }
              })
              .finally(() => {
                loading.close();
              });
          } else {
            //没有正在执行任务  删除
            API_delTask([this.detailInfos.taskId])
              .then((res) => {
                if (res.code == 200) {
                  this.$message.success(this.$t("删除成功"));
                  this.dialogVisible = false;
                  this.$emit("closeTaskModal");
                  this.$emit("getDataList");
                }
              })
              .finally(() => {
                loading.close();
              });
          }
          //删除当前执行任务
        } else {
          API_calendarDelete({ taskExecId: this.taskExecId }).then((res) => {
            if (res.code == 200) {
              this.$message.success("删除成功！");
              this.dialogVisible = false;
              this.$emit("closeTaskModal");
              this.$emit("getDataList");
            }
          });
        }
      } else {
        API_calendarDelete({ taskExecId: this.taskExecId }).then((res) => {
          if (res.code == 200) {
            this.$message.success("删除成功！");
            this.dialogVisible = false;
            this.$emit("closeTaskModal");
            this.$emit("getDataList");
          }
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 16px;
}
.line-one {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-bottom: 24px;
  .line-box {
    display: flex;
    // justify-content: center;
    width: 100%;
    img {
      width: 24px;
      height: 24px;
      vertical-align: middle;
    }
    .confirm-font {
      display: inline-block;
    }
    .warn-font {
      color: #ffad30;
    }
  }
}
.obj-text {
  width: 95%;
  // height: 140px;
  margin-left: 10px;
  padding: 16px;
  box-sizing: border-box;
  text-align: left;
  background-color: rgba(255, 173, 48, 0.06);
  font-size: 11px;
  font-family: SourceHanSansSC-Regular, SourceHanSansSC;
  font-weight: 400;
  color: #ffad30;
  line-height: 17px;
}
</style>
